package com.qf.controller;

import cn.hutool.jwt.JWT;
import com.qf.entity.User;
import com.qf.vo.ResultVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;

@RestController
public class TestController {

    @Autowired
    private RedisTemplate redisTemplate;


    @GetMapping("/apicounts")
    public ResultVo getApiCounts(){

//        redisTemplate.opsForHash()
//                .

        return null;
    }

    /**
     * 请求头中带有token，
     * 如何根据token，查询出该用户的所有信息，在返回
     * @return
     */
    @GetMapping("/currentuser")
    public ResultVo currentUser(HttpServletRequest request){

        String token = request.getHeader("token");

        JWT jwt = JWT.of(token);
        String uuid = (String) jwt.getPayload("uuid");

        String key = LoginController.USER_PRE+uuid;
        User user = (User) redisTemplate.opsForValue()
                .get(key);

        return new ResultVo(1,"ok",user);
    }

}
